package org.jeecg.codegeneratetest;

import org.jeecg.codegeneweb.enumtype.EnumDeployWay;
import org.jeecg.codegeneweb.mock.OneMockWebModelVo;
import org.jeecg.codegeneweb.vo.WebModelVo;
import org.jeecg.modules.online.cgform.model.d;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class CodeGene {
    @Test
    public void testOneTable() throws Exception {
        WebModelVo webModelVo= OneMockWebModelVo.initWo();
        String orgport="8080";
        RestTemplate restTemplate = new RestTemplate();
        String url="http://localhost:"+orgport+"/jeecg-boot/online/codeGeneratecomplex";
//        String projectPath= "D:\\eclipse2018-workspace\\jeecg-boot\\singletable";
//
//        //FileUtilTestAuxCopyFromTest.filedeletefolder(projectPath);
//        org.jeecg.modules.online.cgform.model.d onlGenerateModel = tempSingleTableSetModel(projectPath);

        HttpHeaders requestHeaders = new HttpHeaders();
        requestHeaders.setContentType(MediaType.APPLICATION_JSON);
        requestHeaders.set("Api-Version","0");
        HttpEntity requestEntity =new HttpEntity(webModelVo,requestHeaders);
        String source = restTemplate.postForObject(url, requestEntity, String.class);

        //String s = restTemplate.postForObject(url, onlGenerateModel, String.class);
        String result="";
        int count=1;
//        List<FolderCompare.FileModel> fileModelList=new ArrayList<>();
//        try {
//            //count= FolderCompare.fileFoldCompare(projectPath,webModelVo.getDestinationOutPutDir());
//            fileModelList = FolderCompare.fileFoldComparebacklist(projectPath,webModelVo.getDestinationOutPutDir());
//            //count=fileModelList.size();
//        }catch (Exception ex){
//            result="与原始的文件生成，比较出现异常，需要检查";
//        }
//        if(fileModelList.size()==0){
//            result="与原始的文件生成，比较一样，恭喜你";
//        }else {
//            result="与原始的文件生成，比较错误，需要检查+\r\n";
//            result=result+fileModelList.toString();
//            System.out.println(result);
//        }

        //return result;
        //Assertions.assertTrue(count==0);
    }

    private d tempSingleTableSetModel(String projectPath) {

            d onlGenerateModel=new d();
            onlGenerateModel.setCode("2d5fcb66727140629ebe46ad510e65b2");//实际上是来源与客户端的生成的GUID
            onlGenerateModel.setEntityName("QingjiaDan");
            onlGenerateModel.setEntityPackage("entityPackage -> qingjiadan");
            onlGenerateModel.setFtlDescription("请假单");
            onlGenerateModel.setJformType("1");
            onlGenerateModel.setJspMode("one");//如果是单表树，那么这就是tree，其余一样
            onlGenerateModel.setPackageStyle("service");
            onlGenerateModel.setProjectPath("d:\\workspace\\jeecg-boot");
            onlGenerateModel.setTableName("ces_shop_goods");
            //页面传递的有2个值被服务端抛弃
            //codeTypes: controller,service,dao,mapper,entity,vue
            //tableName_tmp: "TestUser"
            //在jeecg3的版本中，新增了以下3个内容
            //"vueStyle-->vue3""
            //tabelName-->"qingjia_dan";
            return onlGenerateModel;

    }

    private WebModelVo buildWebModelVo() {
        WebModelVo webModelVo=new WebModelVo();
        webModelVo.setDestinationOutPutDir("E:\\eclipse2018-workspace\\jeecg-boot\\singletable");
        webModelVo.setPackageName("com.jeecg.demo");
        webModelVo.setEnumDeployWay(EnumDeployWay.TEST);
        return webModelVo;

    }
}
